// pages/article/article.js
// var rat = require("../../utils/rat.js");
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: "",
    alldata: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    // app.globalData.targeturl = '';
    // app.globalData.jumpparams = [];
    this.getloglist(options.id)
  },
  getloglist(id) {
    var _this = this;
    var params = {
      url: app.api_list.article_getdetail,
      method: 'get',
      data: {
        id:id,
      },
      callBack: function (response) {
        console.log('log_list',response);
        _this.getArticleContentcallbackFun(response.data);
        return false;
        var qq = true;
        if(response.data.data.length>=_this.data.limit){
          _this.data.page++;
        }else{
          qq = false;
        }
        var log_list = _this.data.log_list.concat(response.data.data);
        _this.setData({
          log_list: log_list,
          qq:qq,
        })
      },
      fail: function (error) {
        console.error('请求服务器失败：', error);
      }
    };
    app.http.request(params)
  },
  onShow: function (options) {},

  getArticleContent: function (id) {
    var data = {
      'userid': app.globalData.userId,
      app_code: app.globalData.app_code,
      code: '',
      id: id,
    }
    rat.getArticleContent(data, this.getArticleContentcallbackFun);
  },

  getArticleContentcallbackFun: function (data) {
    console.log(data);
    var that = this;
    // var article = data.content_txt.replace(/px;/g, "rpx;");
    // var detail_content = "<div>我是HTML代码</div>";
    WxParse.wxParse('alldata', 'html', data.content, that, 5);
    // WxParse.wxParse('alldata', 'html', detail_content, that, 5);
    this.setData({
      title: data.title,
      subtitle: data.subtitle,
      cover_image: data.cover_image,
      video: data.video,
    })
  },
  onShareAppMessage() {
    return {
      title: this.data.title,
    }
  },
  onShareTimeline() {
    return {
      title: this.data.title,
    }
  }
})